
#ifndef FFTCONST_H
#include "fftconst.h"
#endif // FFTCONST_H

#ifndef GETTYPE_H
#define GETTYPE_H

#include <stdio.h>
#include <stdlib.h>

#define NAME_STR_LEN  32

#define offsetof(type, member) (size_t)&(((type*)0)->member)

#define container_of(ptr, type, member) ({ \
        const typeof( ((type *)0)->member ) *__mptr = (ptr); \
        (type *)( (char *)__mptr - offsetof(type,member) );})

typedef struct student_info
{
    int  id;
    char name[NAME_STR_LEN];
    int  age;
}student_info;


int printstructinfo()
{
    size_t off_set = 0;
    off_set = offsetof(student_info, id);
    printf("id offset: %u\n",off_set);
    off_set = offsetof(student_info, name);
    printf("name offset: %u\n",off_set);
    off_set = offsetof(student_info, age);
    printf("age offset: %u\n",off_set);
    student_info *stu = (student_info *)malloc(sizeof(student_info));
    stu->age = 10;
    student_info *ptr = container_of(&(stu->age), student_info, age);
    printf("age:%d\n", ptr->age);
    printf("stu address:%p\n", stu);
    printf("ptr address:%p\n", ptr);
    return 0;
}

typedef struct {
    char id;
    myint id1;
    myint2 id2;
}mytypeinfo;

int gettype()
{
   size_t off_set = 0;
    off_set = offsetof(mytypeinfo, id);
    printf("id offset: %u\n",off_set);
    off_set = offsetof(mytypeinfo, id1);
    printf("id1 offset: %u\n",off_set);
    off_set = offsetof(mytypeinfo, id2);
    printf("id2 offset: %u\n",off_set);
    mytypeinfo *stu = (mytypeinfo *)malloc(sizeof(mytypeinfo));
    stu->id1= Sinewave[0];
        stu->id2= Sinewave[0];
    mytypeinfo *ptr = container_of(&(stu->id1), mytypeinfo, id1);
    printf("id1:%d\n", ptr->id1);
    printf("stu address:%p\n", stu);
    printf("ptr address:%p\n", ptr);
    return 0;
}

int getsizeof()
{
     int i;
    long j;
    long k;
    double d;
    printf("int=%u,long=%u,double=%u",sizeof(int),sizeof(long),sizeof(double));
    return 0;
}

int main2()
{
     int i;
    int j;

    i=gettype();
    i=getsizeof();
    j=printstructinfo();
    return 0;
}



#endif
